package com.example.task11v12window;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class HelloController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button addRootBtn;

    @FXML
    private Label resLabel;

    @FXML
    private TextField rootTf;

    @FXML
    private ListView<String> rootsListView;

    @FXML
    private Button solveBtn;

    @FXML
    private TextArea textTA;

    List<String> roots = new ArrayList<>();

    @FXML
    void addRootClick(ActionEvent event) {
        roots.add(rootTf.getText());
        rootsListView.getItems().add(rootTf.getText());
        rootTf.setText("");
    }

    @FXML
    void solveClick(ActionEvent event) {
        String res = SpellChecker.correctSpelling(textTA.getText(), roots.toArray(String[]::new));
        resLabel.setText(res);
    }

    @FXML
    void initialize() {
        assert addRootBtn != null : "fx:id=\"addRootBtn\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert resLabel != null : "fx:id=\"resLabel\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert rootTf != null : "fx:id=\"rootTf\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert rootsListView != null : "fx:id=\"rootsListView\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert solveBtn != null : "fx:id=\"solveBtn\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert textTA != null : "fx:id=\"textTA\" was not injected: check your FXML file 'hello-view.fxml'.";

    }
}